package com.sky.sky_server.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import com.sky.sky_common.enumeration.OperationType;
import com.sky.sky_pojo.entity.Category;
import com.sky.sky_pojo.entity.CategoryQueryPage;
import com.sky.sky_server.annotation.AutoFill;

@Mapper
public interface CategoryMapper {

    /**
     * 获取所有分类
     * @return
     */
    @Select("select * from category")
    List<Category> getAllCategory();

    /**
     * 分页查询
     */
    List<Category> page(CategoryQueryPage categoryQueryPage);

    /**
     * 更新分类
     * @param category
     * @return
     */
    @AutoFill(OperationType.UPDATE)
    int update(Category category);

    /**
     * 插入分类
     * @param category
     * @return
     */
    @AutoFill(OperationType.INSERT)
    @Insert("insert into category (name, type, sort, create_time, update_time, create_user, update_user, status) values (#{name}, #{type}, #{sort}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser}, #{status})")
    int insert(Category category);

    /**
     * 根据id删除分类
     * @param id
     * @return
     */
    @Delete("delete from category where id = #{id}")
    int deleteById(Long id);

    /**
     * 根据type类型查询分类
     * @param type
     * @return
     */
    List<Category> selectByType(Integer type);
}
